package com.ruoyi.framework.reptile.webmagic.jingcai.basketball;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.framework.reptile.webmagic.jingcai.AbstractJingCaiPipeline;
import com.ruoyi.framework.reptile.webmagic.jingcai.basic.MatchInfo;
import com.ruoyi.framework.reptile.webmagic.jingcai.basic.Root;
import com.ruoyi.framework.reptile.webmagic.jingcai.basic.SubMatchInfo;
import com.ruoyi.system.domain.JcScore;
import com.ruoyi.system.service.IJcScoreService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.Pipeline;

import java.math.BigDecimal;
import java.util.Date;
import java.util.Objects;

/**
 * @author dzl
 * @Description 篮球大小分竞彩
 * @date 2024年07月09日 21:33:00
 */
public class JingCaiBasketBallDaXiaoFenPipeline extends AbstractJingCaiPipeline implements Pipeline {

    private static final Logger log = LoggerFactory.getLogger(JingCaiBasketBallDaXiaoFenPipeline.class);

    @Override
    public void process(ResultItems resultItems, Task task) {
        String jcData = resultItems.get("jcData").toString();
        Root root = JSON.parseObject(jcData, Root.class);
        log.info("篮球竞彩大小分数据爬取root:{}", JSON.toJSONString(root));
        IJcScoreService jcScoreService = getJcScoreService();
        if (Objects.isNull(root.getValue())) {
            log.info("爬取到的数据为空，直接返回");
            return;
        }
        for (MatchInfo matchInfo : root.getValue().getMatchInfoList()) {
            JcScore jcScore = new JcScore();
            String businessDate = matchInfo.getBusinessDate();
            SubMatchInfo subMatchInfo = matchInfo.getSubMatchList().get(0);
            jcScore.setJcNumber(subMatchInfo.getMatchNumStr());
            jcScore.setHomeRanking(subMatchInfo.g
            );
            /** 主队排名 */
            @Excel(name = "主队排名")
            private Long homeRanking;

            /** 主场球队id */
            @Excel(name = "主场球队id")
            private Long homeId;

            /** 主场球队名称 */
            @Excel(name = "主场球队名称")
            private String homeTeam;

            /** 客场球队id */
            @Excel(name = "客场球队id")
            private Long opponentId;

            /** 客场球队名称 */
            @Excel(name = "客场球队名称")
            private String opponentTeam;

            /** 客队排名 */
            @Excel(name = "客队排名")
            private Long opponentRanking;

            /** 比赛日期 */
            @JsonFormat(pattern = "yyyy-MM-dd")
            @Excel(name = "比赛日期", width = 30, dateFormat = "yyyy-MM-dd")
            private Date raceDate;

            /** 拉取数据时间 */
            @JsonFormat(pattern = "yyyy-MM-dd")
            @Excel(name = "拉取数据时间", width = 30, dateFormat = "yyyy-MM-dd")
            private Date pullTime;

            /** 基准分数 */
            @Excel(name = "基准分数")
            private BigDecimal referenceScore;

            /** 基准分数以下赔率 */
            @Excel(name = "基准分数以下赔率")
            private BigDecimal belowReferenceScoreOdds;

            /** 基准分数以上赔率 */
            @Excel(name = "基准分数以上赔率")
            private BigDecimal upReferenceScoreOdds;

            /** 类型1NBA 2英超 3西甲 4意甲 5德甲 6法甲 7中超 8J联赛 9WNBA */
            @Excel(name = "类型1NBA 2英超 3西甲 4意甲 5德甲 6法甲 7中超 8J联赛 9WNBA")
            private Long type;

            /** 是否有效 1有效 0无效 */
            @Excel(name = "是否有效 1有效 0无效")
            private Long yn;

            /** 创建人 */
            @Excel(name = "创建人")
            private String creator;

            /** 创建时间 */
            @JsonFormat(pattern = "yyyy-MM-dd")
            @Excel(name = "创建时间", width = 30, dateFormat = "yyyy-MM-dd")
            private Date ts;

            /** 更新人 */
            @Excel(name = "更新人")
            private String modifier;

            /** 更新时间 */
            @JsonFormat(pattern = "yyyy-MM-dd")
            @Excel(name = "更新时间", width = 30, dateFormat = "yyyy-MM-dd")
            private Date modifyTime;

        }
    }
}
